package principle.factory.abs.order;


import principle.factory.abs.simple.pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class orderPizza {
    private absFactory factory;
    public orderPizza(absFactory factory){
        setFactory(factory);
    }
    private void setFactory(absFactory factory){
        pizza p = null;
        String orderType = null;
        this.factory = factory;
        do{
            orderType=getType();
            p = factory.createPizza(orderType);
            if(p!=null){
                p.prepare(orderType);
                p.bake();
                p.cut();
                p.box();
            }else {
                System.out.println("订购失败");
            }
        }while (true);
    }
    //获取订单内容
    public String getType() {
        try {
            BufferedReader type = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("输入要订购的类型");
            String str = type.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
